package com.gzs.learn.payment.api.controller;

import com.gzs.learn.inf.BaseResponseDto;
import com.gzs.learn.inf.split.SplitIdUtil;
import com.gzs.learn.payment.clients.ISerialQueryClient;
import com.gzs.learn.payment.inf.dto.UnifyPayment;
import com.gzs.learn.payment.inf.dto.UnifyPaymentResponse;
import com.gzs.learn.payment.inf.enums.OrderFromEnum;
import com.gzs.learn.payment.service.IPaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * date:  2023/4/9
 *
 * @author guanzhisong
 */
@RestController
@RequestMapping("/payment/gen")
@RequiredArgsConstructor
public class PaymentTestDataGenController {
    final ISerialQueryClient serialQueryClient;
    final IPaymentService paymentService;

    @PostMapping("payment-data")
    public BaseResponseDto<Object> genPaymentData() {
        for (int i = 0; i < 100; i++) {
            UnifyPayment unifyPayment = new UnifyPayment();
            Long orderId = serialQueryClient.getSegmentId("order").getData();
            Long memberId = serialQueryClient.getSegmentId("member").getData();
            orderId = SplitIdUtil.calcNewId(orderId, memberId);
            unifyPayment.setAmt(100L);
            unifyPayment.setChannel(101);
            unifyPayment.setMemberId(memberId);
            unifyPayment.setOperator("operator");
            unifyPayment.setOrderFrom(OrderFromEnum.HOTEL.getCode());
            unifyPayment.setOrderId(orderId);
            unifyPayment.setSubject("goods");

            BaseResponseDto<UnifyPaymentResponse> responseDto = paymentService.unifyPayment(unifyPayment);
        }
        return BaseResponseDto.success("success");
    }
}
